import { axios } from "apis";
import qs from "qs";
import { API } from "types";
import { NotificationDataType } from "../types";

export function apiGetUserNotification(
  param: getUserNotificationParams,
): Promise<API.ApiResponse<NotificationDataType[]>> {
  return axios.request({
    method: "GET",
    url: "/user-notification?" + qs.stringify(param),
  });
}

export type getUserNotificationParams = API.PageQueryParams & {
  subscriberName?: string;
};

export const updateState = (
  id: string,
): Promise<API.ApiResponse<NotificationDataType>> => {
  return axios.request({
    method: "PUT",
    url: "/user-notification/updateState?id=" + id,
  });
};

export const deleteById = (id: string): Promise<API.ApiResponse<"">> => {
  return axios.request({
    method: "DELETE",
    url: "/user-notification/deleteById?id=" + id,
  });
};

export type updateNotificationParam = Partial<NotificationDataType>;

export const updateNotification = (
  params: updateNotificationParam,
): Promise<API.ApiResponse<NotificationDataType>> => {
  console.log("axios /user-notification/updateNotification params :", params);
  return axios.request({
    method: "POST",
    url: "/user-notification/updateNotification",
    data: params,
  });
};
